package com.imooc.controller.center;

import com.imooc.controller.BaseController;
import com.imooc.service.center.CenterOrderService;
import com.imooc.utils.IMOOCJSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author mark
 * @date 2021/4/16 0016 22:33
 */
@Api(value = "用户中心订单接口", tags = {"用户中心订单相关接口"})
@RestController
@RequestMapping({"/center"})
public class CenterOrderController extends BaseController {

    @Autowired
    private CenterOrderService centerOrderService;

    @ApiOperation(value = "根据用户id获取用户数据", notes = "根据用户id获取用户数据", httpMethod = "GET")
    @GetMapping("/order/get-my-orders")
    public IMOOCJSONResult getMyOrders(@ApiParam(value = "用户id", name = "userId", required = true)
                                       @RequestParam(value = "userId") String userId,
                                       @ApiParam(value = "订单状态", name = "status", required = true)
                                       @RequestParam(value = "status") Integer status,
                                       @ApiParam(name = "page", value = "第几页") @RequestParam Integer page,
                                       @ApiParam(name = "pageSize", value = "该页多少页数") @RequestParam Integer pageSize) {
        if (null == userId) {
            return IMOOCJSONResult.errorMsg("用户id不能为空");
        }
        if (null == page) {
            page = PAGE;
        }

        if (null == pageSize) {
            pageSize = COMMON_PAGE_SIZE;
        }

        return IMOOCJSONResult.ok(centerOrderService.getMyOrders(userId, status, page, pageSize));
    }

    @ApiOperation(value = "根据用户id获取用户订单状态数量", notes = "根据用户id获取用户订单状态数量", httpMethod = "GET")
    @GetMapping("/order/get-my-order-status")
    public IMOOCJSONResult getMyOrderStatus(@ApiParam(value = "用户id", name = "userId", required = true)
                                            @RequestParam(value = "userId") String userId) {
        if (null == userId) {
            return IMOOCJSONResult.errorMsg("用户id不能为空");
        }
        return IMOOCJSONResult.ok(centerOrderService.getMyOrderStatus(userId));
    }

    @ApiOperation(value = "根据用户id获取用户中心订单动态", notes = "根据用户id获取用户中心订单动态", httpMethod = "POST")
    @PostMapping("/order/get-my-trend")
    public IMOOCJSONResult getMyTrend(@ApiParam(value = "用户id", name = "userId", required = true)
                                      @RequestParam(value = "userId") String userId,
                                      @ApiParam(name = "page", value = "第几页") @RequestParam Integer page,
                                      @ApiParam(name = "pageSize", value = "该页多少页数") @RequestParam Integer pageSize) {
        if (null == userId) {
            return IMOOCJSONResult.errorMsg("用户id不能为空");
        }
        if (null == page) {
            page = PAGE;
        }

        if (null == pageSize) {
            pageSize = COMMON_PAGE_SIZE;
        }
        return IMOOCJSONResult.ok(centerOrderService.getMyTrend(userId, page, pageSize));
    }


}
